﻿namespace NEvoWeb.Modules.NB_Store
{
    using DotNetNuke.Common;
    using DotNetNuke.Entities.Modules;
    using DotNetNuke.Services.Exceptions;
    using DotNetNuke.Services.Localization;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Runtime.CompilerServices;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class ProductListOptions : BaseModule
    {
        [AccessedThroughProperty("cmdCancel")]
        private LinkButton _cmdCancel;
        [AccessedThroughProperty("cmdUpdate")]
        private LinkButton _cmdUpdate;
        [AccessedThroughProperty("chkDefaultOrderDESC")]
        private CheckBox _chkDefaultOrderDESC;
        [AccessedThroughProperty("chkIncrementCart")]
        private CheckBox _chkIncrementCart;
        [AccessedThroughProperty("chkRedirectToCart")]
        private CheckBox _chkRedirectToCart;
        [AccessedThroughProperty("chkSkipList")]
        private CheckBox _chkSkipList;
        [AccessedThroughProperty("ddlDefaultCategory")]
        private DropDownList _ddlDefaultCategory;
        [AccessedThroughProperty("ddlDefaultOrder")]
        private DropDownList _ddlDefaultOrder;
        [AccessedThroughProperty("lstModuleTitle")]
        private DropDownList _lstModuleTitle;
        [AccessedThroughProperty("plCategoryMessage")]
        private UserControl _plCategoryMessage;
        [AccessedThroughProperty("plDefaultCategory")]
        private UserControl _plDefaultCategory;
        [AccessedThroughProperty("plDefaultOrder")]
        private UserControl _plDefaultOrder;
        [AccessedThroughProperty("plDefaultOrderDESC")]
        private UserControl _plDefaultOrderDESC;
        [AccessedThroughProperty("plIncrementCart")]
        private UserControl _plIncrementCart;
        [AccessedThroughProperty("plModuleTitle")]
        private UserControl _plModuleTitle;
        [AccessedThroughProperty("plPageSize")]
        private UserControl _plPageSize;
        [AccessedThroughProperty("plRedirectToCart")]
        private UserControl _plRedirectToCart;
        [AccessedThroughProperty("plSkipList")]
        private UserControl _plSkipList;
        [AccessedThroughProperty("rblCategoryMessage")]
        private RadioButtonList _rblCategoryMessage;
        [AccessedThroughProperty("tblBasic")]
        private HtmlTable _tblBasic;
        [AccessedThroughProperty("txtPageSize")]
        private TextBox _txtPageSize;

        public ProductListOptions()
        {
            base.Load += new EventHandler(this.Page_Load);
        }

        private void cmdCancel_Click(object sender, EventArgs e)
        {
            try
            {
                this.Response.Redirect(Globals.NavigateURL(), true);
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exc = exception1;
                DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException((PortalModuleBase) this, exc);
                ProjectData.ClearProjectError();
            }
        }

        private void cmdUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                this.UpdateSettings();
                this.Response.Redirect(Globals.NavigateURL(), true);
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exc = exception1;
                DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException((PortalModuleBase) this, exc);
                ProjectData.ClearProjectError();
            }
        }

        private void LoadSettings()
        {
            try
            {
                if (!this.Page.IsPostBack)
                {
                    this.chkRedirectToCart.Checked = Conversions.ToBoolean(this.Settings["chkRedirectToCart"]);
                    if (this.rblCategoryMessage.Items.FindByValue(Conversions.ToString(this.Settings["rblCategoryMessage"])) != null)
                    {
                        this.rblCategoryMessage.SelectedValue = Conversions.ToString(this.Settings["rblCategoryMessage"]);
                    }
                    else
                    {
                        this.rblCategoryMessage.SelectedValue = "1";
                    }
                    this.txtPageSize.Text = Conversions.ToString(this.Settings["txtPageSize"]);
                    this.chkIncrementCart.Checked = Conversions.ToBoolean(this.Settings["chkIncrementCart"]);
                    this.chkDefaultOrderDESC.Checked = Conversions.ToBoolean(this.Settings["chkDefaultOrderDESC"]);
                    this.chkSkipList.Checked = Conversions.ToBoolean(this.Settings["chkSkipList"]);
                    SharedFunctions.populateCategoryList(this.PortalId, this.ddlDefaultCategory, Conversions.ToString(-1), "All Categories", "");
                    if (this.ddlDefaultCategory.Items.FindByValue(Conversions.ToString(this.Settings["ddlDefaultCategory"])) != null)
                    {
                        this.ddlDefaultCategory.ClearSelection();
                        this.ddlDefaultCategory.Items.FindByValue(Conversions.ToString(this.Settings["ddlDefaultCategory"])).Selected = true;
                    }
                    SharedFunctions.LocalizeDDL(this.ddlDefaultOrder, DotNetNuke.Services.Localization.Localization.GetString("DefaultOrderList", this.LocalResourceFile));
                    if (this.ddlDefaultOrder.Items.FindByValue(Conversions.ToString(this.Settings["ddlDefaultOrder"])) != null)
                    {
                        this.ddlDefaultOrder.SelectedValue = Conversions.ToString(this.Settings["ddlDefaultOrder"]);
                    }
                    if (this.lstModuleTitle.Items.FindByValue(Conversions.ToString(this.Settings["lstModuleTitle"])) != null)
                    {
                        this.lstModuleTitle.ClearSelection();
                        this.lstModuleTitle.Items.FindByValue(Conversions.ToString(this.Settings["lstModuleTitle"])).Selected = true;
                    }
                }
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exc = exception1;
                DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException((PortalModuleBase) this, exc);
                ProjectData.ClearProjectError();
            }
        }

        private void Page_Load(object sender, EventArgs e)
        {
            this.LoadSettings();
        }

        private void UpdateSettings()
        {
            try
            {
                ModuleController controller = new ModuleController();
                controller.UpdateModuleSetting(this.ModuleId, "chkRedirectToCart", this.chkRedirectToCart.Checked.ToString());
                controller.UpdateModuleSetting(this.ModuleId, "rblCategoryMessage", this.rblCategoryMessage.SelectedValue);
                controller.UpdateModuleSetting(this.ModuleId, "txtPageSize", this.txtPageSize.Text);
                controller.UpdateModuleSetting(this.ModuleId, "ddlDefaultCategory", this.ddlDefaultCategory.SelectedValue);
                controller.UpdateModuleSetting(this.ModuleId, "chkIncrementCart", this.chkIncrementCart.Checked.ToString());
                controller.UpdateModuleSetting(this.ModuleId, "ddlDefaultOrder", this.ddlDefaultOrder.SelectedValue);
                controller.UpdateModuleSetting(this.ModuleId, "chkDefaultOrderDESC", this.chkDefaultOrderDESC.Checked.ToString());
                controller.UpdateModuleSetting(this.ModuleId, "chkSkipList", this.chkSkipList.Checked.ToString());
                controller.UpdateModuleSetting(this.ModuleId, "lstModuleTitle", this.lstModuleTitle.SelectedValue);
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exc = exception1;
                DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException((PortalModuleBase) this, exc);
                ProjectData.ClearProjectError();
            }
        }

        protected virtual LinkButton cmdCancel
        {
            get
            {
                return this._cmdCancel;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                EventHandler handler = new EventHandler(this.cmdCancel_Click);
                if (this._cmdCancel != null)
                {
                    this._cmdCancel.Click -= handler;
                }
                this._cmdCancel = value;
                if (this._cmdCancel != null)
                {
                    this._cmdCancel.Click += handler;
                }
            }
        }

        protected virtual LinkButton cmdUpdate
        {
            get
            {
                return this._cmdUpdate;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                EventHandler handler = new EventHandler(this.cmdUpdate_Click);
                if (this._cmdUpdate != null)
                {
                    this._cmdUpdate.Click -= handler;
                }
                this._cmdUpdate = value;
                if (this._cmdUpdate != null)
                {
                    this._cmdUpdate.Click += handler;
                }
            }
        }

        protected virtual CheckBox chkDefaultOrderDESC
        {
            get
            {
                return this._chkDefaultOrderDESC;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._chkDefaultOrderDESC = value;
            }
        }

        protected virtual CheckBox chkIncrementCart
        {
            get
            {
                return this._chkIncrementCart;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._chkIncrementCart = value;
            }
        }

        protected virtual CheckBox chkRedirectToCart
        {
            get
            {
                return this._chkRedirectToCart;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._chkRedirectToCart = value;
            }
        }

        protected virtual CheckBox chkSkipList
        {
            get
            {
                return this._chkSkipList;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._chkSkipList = value;
            }
        }

        protected virtual DropDownList ddlDefaultCategory
        {
            get
            {
                return this._ddlDefaultCategory;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._ddlDefaultCategory = value;
            }
        }

        protected virtual DropDownList ddlDefaultOrder
        {
            get
            {
                return this._ddlDefaultOrder;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._ddlDefaultOrder = value;
            }
        }

        protected virtual DropDownList lstModuleTitle
        {
            get
            {
                return this._lstModuleTitle;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._lstModuleTitle = value;
            }
        }

        protected virtual UserControl plCategoryMessage
        {
            get
            {
                return this._plCategoryMessage;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._plCategoryMessage = value;
            }
        }

        protected virtual UserControl plDefaultCategory
        {
            get
            {
                return this._plDefaultCategory;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._plDefaultCategory = value;
            }
        }

        protected virtual UserControl plDefaultOrder
        {
            get
            {
                return this._plDefaultOrder;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._plDefaultOrder = value;
            }
        }

        protected virtual UserControl plDefaultOrderDESC
        {
            get
            {
                return this._plDefaultOrderDESC;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._plDefaultOrderDESC = value;
            }
        }

        protected virtual UserControl plIncrementCart
        {
            get
            {
                return this._plIncrementCart;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._plIncrementCart = value;
            }
        }

        protected virtual UserControl plModuleTitle
        {
            get
            {
                return this._plModuleTitle;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._plModuleTitle = value;
            }
        }

        protected virtual UserControl plPageSize
        {
            get
            {
                return this._plPageSize;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._plPageSize = value;
            }
        }

        protected virtual UserControl plRedirectToCart
        {
            get
            {
                return this._plRedirectToCart;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._plRedirectToCart = value;
            }
        }

        protected virtual UserControl plSkipList
        {
            get
            {
                return this._plSkipList;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._plSkipList = value;
            }
        }

        protected virtual RadioButtonList rblCategoryMessage
        {
            get
            {
                return this._rblCategoryMessage;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._rblCategoryMessage = value;
            }
        }

        protected virtual HtmlTable tblBasic
        {
            get
            {
                return this._tblBasic;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._tblBasic = value;
            }
        }

        protected virtual TextBox txtPageSize
        {
            get
            {
                return this._txtPageSize;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._txtPageSize = value;
            }
        }
    }
}

